Support keyword expansion in 'CONSTANT' for OFIELDS.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 23 Mar 2005 18:39:16 +0000 (18:39 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 23 Mar 2005 18:39:16 +0000 (18:39 +0000)
gpsbabel/csv_util.c
gpsbabel/csv_util.h
gpsbabel/xcsv.c

index 3b4fd28495cca8269d57c9ce1d669528a6a39f8e..26625e4fae3b711f3de054faade291ac49500d43 100644 (file)
@@ -847,7 +847,7 @@ xcsv_waypt_pr(const waypoint *wpt)
     oldlon = wpt->longitude;
     oldlat = wpt->latitude;
 
-    if (strcmp(xcsv_file.field_delimiter, "\\w") == 0)
+    if (xcsv_file.field_delimiter && strcmp(xcsv_file.field_delimiter, "\\w") == 0)
         write_delimiter = " ";
     else
         write_delimiter = xcsv_file.field_delimiter;
@@ -903,7 +903,12 @@ xcsv_waypt_pr(const waypoint *wpt)
             sprintf(buff, fmp->printfc, waypt_out_count + atoi(fmp->val));
         } else
         if (strcmp(fmp->key, "CONSTANT") == 0) {
-            sprintf(buff, fmp->printfc, fmp->val);
+           const char *cp = xcsv_get_char_from_constant_table(fmp->val);
+           if (cp) {
+                sprintf(buff, fmp->printfc, cp);
+           } else {
+               sprintf(buff, fmp->printfc, fmp->val);
+           }
         } else
         if (strcmp(fmp->key, "SHORTNAME") == 0) {
             sprintf(buff, fmp->printfc, 
index e1e12cb169b1530680fba42971682b518383f1b8..a4d2d421074fd3fda9031d8b421cf89e813ff987 100644 (file)
@@ -62,6 +62,9 @@ xcsv_ofield_add(char *, char *, char *);
 void 
 xcsv_destroy_style(void);
 
+const char *
+xcsv_get_char_from_constant_table(char *key);
+
 /****************************************************************************/
 /* types required for various xcsv functions                                */
 /****************************************************************************/
index a3489a8e5206725ec67961669bd0fb10ba42315b..e910c095626015368417de2cbf2d360898c50026 100644 (file)
@@ -166,8 +166,8 @@ xcsv_destroy_style(void)
     xcsv_file.is_internal = internal;
 }
 
-static const char *
-get_char_from_constant_table(char *key)
+const char *
+xcsv_get_char_from_constant_table(char *key)
 {
     char_map_t *cm = xcsv_char_table;
 
@@ -205,7 +205,7 @@ xcsv_parse_style_line(const char *sbuff)
     if (strlen(sbuff)) {
        if (ISSTOKEN(sbuff, "FIELD_DELIMITER")) {
            sp = csv_stringtrim(&sbuff[16], "\"", 1);
-           cp = get_char_from_constant_table(sp);
+           cp = xcsv_get_char_from_constant_table(sp);
            if (cp) {
                xcsv_file.field_delimiter = xstrdup(cp);
                xfree(sp);
@@ -232,7 +232,7 @@ xcsv_parse_style_line(const char *sbuff)
 
        if (ISSTOKEN(sbuff, "RECORD_DELIMITER")) {
            sp = csv_stringtrim(&sbuff[17], "\"", 1);
-           cp = get_char_from_constant_table(sp);
+           cp = xcsv_get_char_from_constant_table(sp);
            if (cp) {
                xcsv_file.record_delimiter = xstrdup(cp);
                xfree(sp);
@@ -291,7 +291,7 @@ xcsv_parse_style_line(const char *sbuff)
 
        if (ISSTOKEN(sbuff, "BADCHARS")) {
            sp = csv_stringtrim(&sbuff[9], "\"", 1);
-           cp = get_char_from_constant_table(sp);
+           cp = xcsv_get_char_from_constant_table(sp);
 
            if (cp) {
                p = xstrdup(cp);